﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GamePlusClassLibrary;

namespace GamePlus.UserControls
{
    public partial class mod_categories_games : System.Web.UI.UserControl
    {
        private int? _select_tag_ID
        {
            get {
                if (ViewState["select_tag_ID"] != null)
                    return int.Parse(ViewState["select_tag_ID"].ToString());
                else
                    return null;
            }
            set {
                ViewState.Add("select_tag_ID", value);
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadJogosCategoria();
                loadMenuCategoria();
            }
        }

        private void loadMenuCategoria()
        {
            //List<visible_tags> lsVT = visible_tags.ListByType(3);
            //List<tags> ls = new List<tags>();
            //lsVT.ForEach(delegate(visible_tags obj) {
            //    tags aux = tags.Load(obj._tag_ID);
            //    ls.Add(aux);
            //});

            //string sContent = "<ul>";
            //int cont = 0;
            //ls.ForEach(delegate(tags tagitem) {
            //    if (cont.Equals(0))
            //    {
            //        if (!this._select_tag_ID.HasValue)
            //            this._select_tag_ID = tagitem._ID;

            //        sContent += "<li class=\"bdc2 first\"><a id="+ tagitem._ID.ToString() +" class=\"active\">" + tagitem._name + "<img class=\"sprtmain ic-arrup\" src=\"/images/layout/bg-img.png\" /></a></li>";
            //    }
            //    else
            //        sContent += "<li class=\"bdc2\"><a id="+ tagitem._ID.ToString() +">" + tagitem._name + "<img class=\"sprtmain ic-arrup\" src=\"/images/layout/bg-img.png\" /></a></li>";
            //    cont++;
            //});
            //sContent += "</ul>";
            //divMenuCategoria.InnerHtml = sContent;
        }

        public void loadJogosCategoria()
        {
            //List<games> ls = new List<games>();
            //List<visible_tags> lsTags = visible_tags.ListByType(3);
            //lsTags.ForEach(delegate(visible_tags objTags) {
            //    ls.AddRange(games.ListByCategory(objTags._tag_ID, 8, "created_at"));
            //});
            
            //string sJSON = "var jsnGamesCat = [";
            //ls.ForEach(delegate(games obj)
            //{
            //    string snome = ((obj._name.Length > 18) ? obj._name.Substring(0, 18) + " ..." : obj._name);
            //    string sdesc = ((obj._highlight.Length > 45) ? obj._highlight.Substring(0, 45) + " ..." : obj._highlight);
            //    sJSON += "{" + "\"id\":\"" + obj._ID.ToString() + "\",\"name\":\"" + snome + "\",\"text\":\"" + 
            //        sdesc + "\",\"cat\":\"" + obj._main_Tag_ID.ToString() + "\"},";
            //});
            //sJSON = sJSON.Remove(sJSON.Length-1);
            //sJSON += "]";

            //Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "", sJSON, true);
        }
    }
}